<template>
    <div>
        <div class="">
            <div class="cc">
                <div class="xing">
                    <el-form :model="form" :rules="rules" ref="form" label-width="120px" label-position="right">
                        <el-form-item label="关键词：" prop="name">
                            <el-input v-model="form.surname" placeholder="请输入做梦内容的关键词，比如：婴儿" clearable
                                style="width: 450px"></el-input>
                        </el-form-item>
                    </el-form>
                </div>

                <!--设置监听器，当点击radio时调用-->
            </div>
            <div class="start" @click="start">
                <span>立即解梦</span>
            </div>
            <div>
                <h3 class="title">
                    <p class="line">测算简介</p>
                </h3>
                <div style="font-size: 14px; margin: 0 10px 20px 10px">
                    <p style="">
                        1.《周公解梦》是靠人的梦来卜吉凶的一本于民间流传的解梦书籍，共有七类梦境的解述。书中的周公就是周公旦，孔子梦的“吾不复梦见周公矣”在儒家经常会出现。
                        周公是一个在孔子梦中频频出现的人物，在儒家长期主导文化的中国，周公也就不可避免的直接与梦联系起来。
                    </p>
                    <p>
                        2.心诚则灵，测算结果仅供参考。
                    </p>

                </div>
            </div>

        </div>

        <el-dialog title="解梦" :visible.sync="centerDialogVisible" width="80%">
            <div class="mingzi">
                <div class="" style="
            text-align: center;
            width: 100%;
            margin-top: 20px;
            border-bottom: 1px #ddd;
          ">
                    <span style="font-size: 14px; padding: 20px">请选择一个场景</span>
                </div>
                <div class="mingzi_" v-for="(item, index) in result" @click="jumpzidian(item.message)">
                    <span>{{ item.title }}</span>
                </div>
            </div>
            <p style="text-indent: 2em; line-height: 25px; padding: 10px">
                {{ jiemeng }}
            </p>
        </el-dialog>
    </div>
</template>
<script>
export default {
    data() {
        return {
            result: {},
            jiemeng: "",
            centerDialogVisible: false,

            xing: "",
            list: [],
            form: {
                surname: "",
            },

            fix_mid_name: "",
            sex: "0", //姓别
            namewords: "2", //字数
            limit: 149, //返回条数
            page: 1,
        };
    },

    methods: {
        jumpzidian(item) {

            this.jiemeng = item;
        },
        isChineseChar(char) {
            var regex = /[\u4e00-\u9fa5]/;
            return regex.test(char);
        },

        start() {
            let hanzi = this.isChineseChar(this.form.surname);
            if (!this.form.surname) {
                uni.showToast({
                    title: "请输入关键词",
                    icon: "none",
                });
                return;
            }

            let config = {
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
            };
            let params = {
                title_zhougong: this.form.surname,

                api_key: "FNcQHQuf0W8wDrXMjWc0xqTzw",
            };
            this.$axios
                .post(window.config.apiUrl + "/v1/Gongju/zhougong", params, config)
                .then((res) => {
                    if (res.data.errcode == -1) {
                        this.$message({
                            type: "warning",
                            message: res.data.errmsg,
                        });

                        return;
                    }
                    this.centerDialogVisible = true;
                    this.result = res.data.data;
                    console.log(this.result);
                });
        },
    },
};
</script>
<style lang="scss">
.cc {
    width: 100%;
    padding-top: 20px;
}

.xing {
    display: flex;
    align-items: center;
    padding-left: 10px;
    margin-top: 20px;

    .lable {
        width: 70px;
        font-size: 15px;
    }
}

.xingming {
    width: 80%;
    padding-left: 20px;
    margin: auto;
    border-radius: 10px;
    height: 30px;
    border: 1px solid #ccc;
}

.mingzi {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    height: 500px;
    overflow: auto;
    margin-top: 10px;

    .mingzi_ {
        margin-top: 20px;
        width: 18%;
        text-align: center;
        color: #496bca;
        border: 1px solid #ddd;
        margin: 10px;


        span {
            font-size: 14px;
            padding-top: 5px;
            padding-bottom: 10px;

            user-select: all;
        }
    }
}

.start {
    width: 100%;
    text-align: center;

    span {
        width: 120px;
        display: inline-block;
        background-color: #8e5230;
        font-size: 15px;
        color: #fff;
        padding: 10px;

        line-height: 15px;
        margin-top: 20px;
    }
}
</style>
